cmake_minimum_required(VERSION 3.5.0)
project(PerceptionDataset
        LANGUAGES C CXX
        VERSION 0.0.4)

if(DEFINED AMBA_SDK_DIR)
    find_package(AmbaSDK9 REQUIRED PATHS ${PROJECT_SOURCE_DIR})
    set(CMAKE_C_COMPILER ${COMPILER_PREFIX}gcc)
    set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}g++)
    set(CMAKE_AR ${COMPILER_PREFIX}ar)
    set(CMAKE_AS ${COMPILER_PREFIX}as)
    set(CMAKE_LD ${COMPILER_PREFIX}ld)
    SET(CMAKE_STRIP ${COMPILER_PREFIX}strip)
else()
    find_package(Boost 1.78 EXACT REQUIRED)
    find_package(Threads REQUIRED)
    find_package(OpenCV REQUIRED)
endif()

set(LIB_TARGET_NAME perception_dataset)
set(TEST_TARGET_NAME PerceptionDataset)

set(TARGET_OUT_DIR ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install/perception/dataset)

EXECUTE_PROCESS(COMMAND arch
        TIMEOUT 5
        OUTPUT_VARIABLE ARCH_TYPE
        OUTPUT_STRIP_TRAILING_WHITESPACE
        )

MESSAGE(STATUS "BUILD ARCH_TYPE ${ARCH_TYPE}")

string(TIMESTAMP COMPILE_TIME "%Y-%m-%d %H:%M")

configure_file(
  version.h.in
  generated/version.h
  @ONLY
  )

############################################################################################
# settings

set(TARGET_DEBUG_POSTFIX _debug CACHE STRING "suffix for debug builds")

if(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -O0")
    message(STATUS "DEBUG MODE:${CMAKE_C_FLAGS_DEBUG}")

elseif(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall")
    message(STATUS "RELEASE MODE:${CMAKE_C_FLAGS_RELEASE}")

elseif(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -Wall")
    message(STATUS "RelWithDebInfo MODE:${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
    
elseif(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel"))
    set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Wall")
    message(STATUS "MinSizeRel MODE:${CMAKE_CXX_FLAGS_MINSIZEREL}")
else()
    message(FATAL_ERROR "Unknown CMAKE_BUILD_TYPE ...")
endif()

############################################################################################

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

include(CPack)

include_directories(
  ${PROJECT_SOURCE_DIR}/include
  ${CMAKE_BINARY_DIR}
  ${AMBA_SDK_INCLUDE_DIRS}
  ${AMBA_SDK_OSS_INCLUDE_DIRS}
  ${Boost_INCLUDE_DIR}
  ${OpenCV_INCLUDE_DIRS}
)

add_subdirectory(${PROJECT_SOURCE_DIR}/src)
#add_subdirectory(${PROJECT_SOURCE_DIR}/test)
